package com.zhentao.controller;

import com.zhentao.pojo.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class FreemarkerTestController {
    @RequestMapping("/t1")
    public String t1(Model model) {
        //1传递一个文本数据
        model.addAttribute("name", "测试使用-小明");
        //跳转到一个页面 --拼接成01-test.ftl


        //2一个对象
        Student student = new Student();
        student.setName("小兰");
        student.setAge(18);
        model.addAttribute("student", student);


        //使用一个列表
        Student student1 = new Student();
        student1.setName("小兰1");
        student1.setAge(19);
        List<Object> list = new ArrayList<>();
        list.add(student);
        list.add(student1);
        model.addAttribute("stus", list);


        //map
        Map<String, Object> map = new HashMap<>();
        map.put("stu1", student);
        map.put("stu2", student1);
        model.addAttribute("map", map);

        //map里边包含list
//       List<Map<String,Object>> list1=new ArrayList<>();
//        list1.add(map);
//        model.addAttribute("list1",list1);
        return "01-test";
    }
}
